package com.situ.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springboot.mapper.StudentMapper;
import com.situ.springboot.pojo.Student;
import com.situ.springboot.service.IStudentService;
import com.situ.springboot.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectAll() {
        return studentMapper.selectAll();
    }

    @Override
    public LayUITableResult selectByPage(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Student> list = studentMapper.selectAll();
        PageInfo pageInfo = new PageInfo(list);
        long totalCount = pageInfo.getTotal();
        return LayUITableResult.ok((int)totalCount, list);
    }

    @Override
    public Student selectById(Integer id) {
        return studentMapper.selectById(id);
    }

    /*@Override
    public LayUITableResult selectByPage(Integer page, Integer limit) {
        int offset = (page - 1) * limit;
        List<Student> list = studentMapper.selectByPage(offset, limit);
        int totalCount = studentMapper.selectTotalCount();
        return LayUITableResult.ok(totalCount, list);
    }*/
}
